package com.igeek.shop.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.igeek.shop.dao.IProductDAO;
import com.igeek.shop.entity.Product;
import com.igeekhome.utils.DataSourceUtils;

public class ProductDAOImpl implements IProductDAO{

	@Override
	public List<Product> findHotProducts() throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from product where is_hot = 1 limit 9;";
		List<Product> result = (List<Product>)runner.query(sql, new BeanListHandler<>(Product.class));
		return result;
	}

	@Override
	public List<Product> findNewProducts() throws SQLException {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "select * from product order by pdate desc limit 9;";
		List<Product> result = (List<Product>)runner.query(sql, new BeanListHandler<>(Product.class));
		return result;
	}

}